//
//  WZQuestionCell.m
//  ETong
//
//  Created by wanzhao on 15/11/1.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "WZQuestionCell.h"
#import "WZQuestionFrame.h"

@interface WZQuestionCell ()

@property (nonatomic, weak) UILabel *questionLabel;
@property (nonatomic, weak) UIView *line1;
@property (nonatomic, weak) UIButton *acVIew;

@end

@implementation WZQuestionCell

+ (WZQuestionCell *)questionCellWithTableView:(UITableView *)tableView{
    static NSString *comCellId = @"questionCell";
    WZQuestionCell *cell = [tableView dequeueReusableCellWithIdentifier:comCellId];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:comCellId];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = WhiteColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setupQuestionCellSubView];
        
    }
    return self;
}

- (void)setupQuestionCellSubView
{
    UIView *line1 = [[UIView alloc] init];
    line1.backgroundColor = RGBCOLORWITH16COLOR(0xcccccc);
    [self.contentView addSubview:line1];
    self.line1 = line1;
    
    
    UILabel *qustionLabel = [self addLabelWithFont:Font15 textAliment:NSTextAlignmentLeft textColor:RGBCOLORWITH16COLOR(0x333333)];
    self.questionLabel = qustionLabel;
    
    UIButton *acVIew = [UIButton buttonWithType:UIButtonTypeCustom];
    acVIew.userInteractionEnabled = NO;
    [self.contentView addSubview:acVIew];
    self.acVIew = acVIew;
}

- (UILabel *)addLabelWithFont:(UIFont *)textFont textAliment:(NSTextAlignment)textAliment textColor:(UIColor *)textColor
{
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.font = textFont;
    nameLabel.textAlignment = textAliment;
    nameLabel.numberOfLines = 0;
    nameLabel.textColor = textColor;
    [self.contentView addSubview:nameLabel];
    return nameLabel;
}

- (void)setQueFrame:(WZQuestionFrame *)queFrame
{
    _queFrame = queFrame;
    self.questionLabel.text = queFrame.question.question;
    self.questionLabel.frame = queFrame.questionFrame;
    [self.acVIew setImage:queFrame.question.accessoryImage forState:UIControlStateNormal];
    
    self.acVIew.frame = queFrame.accesoryFrame;
    self.line1.frame = queFrame.line1Frame;
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.accessoryView.x = self.width - OppositeWidthRate(10) - self.accessoryView.width;
    self.accessoryView.y = 0;
    self.accessoryView.height = self.height;

}

@end
